package com.example.day06.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.day06.pojo.User;
import com.example.day06.service.UserService;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(allowedHeaders = "*")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/show")
    public List<User> findAll(Model model){
        List<User> list = userService.findAll();
        model.addAttribute("list",list);
        return list;
    }

    @RequestMapping("/add")
    public void add(@RequestBody User user){
        userService.add(user);
    }

    @RequestMapping("/findByid")
    public User findById(Integer id,Model model){
        User user = userService.findById(id);
        model.addAttribute("user",user);
        return user;
    }

    @RequestMapping("/update")
    public void update(@RequestBody User user){
        userService.update(user);
    }

    @RequestMapping("/del")
    public void del(Integer id){
        userService.del(id);
    }
}
